package V001_NewStart;

import java.awt.Color;
import java.awt.Graphics;

/**
 *
 * @author Smai
 */
public class Map {

  private Tile[][] worldTiles = MapLoader.CreateMap(100, 100);
  private Player player;
  private int posFocusX;
  private int posFocusY;
  private int WorldArrayX;
  private int WorldArrayY;

  public Map(Game game, Player player) {
    this.player = player;
  }

  public void piirraKartta(Graphics gbi, int width, int height) {
    gbi.setColor(Color.white);
    gbi.drawRect(0, 0, 1024, 640);

    for (int i = 0; i < 34; i++) {
      for (int j = 0; j < 22; j++) {
        worldTiles[i + WorldArrayX][j + WorldArrayY].paint(gbi,i,j, posFocusX, posFocusY);
      }
    }

    player.paint(gbi);

    gbi.drawString("Focus " + posFocusX + "," +posFocusY, 320, 320);
    gbi.drawString("WorldArray " + WorldArrayX + "," +WorldArrayY, 320, 336);
    //kikkare.piira(gbi);
  }

  public void moving(int x, int y) {
    this.posFocusX = this.posFocusX + x;
    this.posFocusY = this.posFocusY + y;

    checkArray();
  }

  public void checkArray() {

    //Tarkastetaan linjaukset x
    if (posFocusX == -32) {
      posFocusX = 0;
      WorldArrayX--;
    } else if (posFocusX == 32) {
      posFocusX = 0;
      WorldArrayX++;
    }

    //Tarkastetaan linjaukset Y
    if (posFocusY == -32) {
      posFocusY = 0;
      WorldArrayY--;
    } else if (posFocusY == 32) {
      posFocusY = 0;
      WorldArrayY++;
    }

  }
}
